package com.zhangbaiyan.jincc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhangbaiyan
 * @date 2024-09-25 12:53
 * @description:
 * @version:
 */
public class MyThreadPoolDemo {
    public static void main(String[] args) {
        /*
              static  ExecutorService newCachedThreadPool()                      创建一个没有上限的线程池
              static  ExecutorService newFixedThreadPool(int nThreads)           创建有上限的线程池
         */

        //1.获取线程池对象
        ExecutorService pool1= Executors.newFixedThreadPool(3);

        //2.提交任务
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());

        //销毁线程池
        pool1.shutdown();
    }
}
